﻿Ext.regController('dbController', {
			
/*********************** SEARCH VIEW ***************************/
// display tweetDeck
'searchPosts': function (options) {
		alert("in search posts db controller");
		//FlyTalk.views.TalkView.setActiveItem(FlyTalk.views.ColumnView, {type: 'slide', direction: 'right'});
},

/*********************** FLIGHT TALK VIEW ***************************/
/**
* DESCRIPTION: get RECENT posts from people on my flight
* PARAMETERS: 
*       next - next page to display
*       list - list to display the posts
* RESULT: populate the provided list with posts (Question, comments, suggestions, and review)
*/
'getMixedPosts': function (options) {
	//alert("in display posts db controller");
		// send request to database
						
		Ext.util.JSONP.request({
				url: 'http://yangjustine.startlogic.com/flytalk/flytalk1/db/dbFlytalk.php',
				callbackKey: 'callback',
				params: {
               			 method: 'getTerminalPost',	 // using this parameter
            	},
				success: function() { Ext.Msg.alert('Success'); },
				failure: function() { Ext.Msg.alert('fail');},
				callback: function(data){
					//alert(data.results[0].from_user);
					//alert(data.results.length);
					
					var store = new Ext.data.JsonStore({
						model : 'MixedPostModel',
					});
				
					// load data into store
					store.loadData(data.results);
					
					// bind store to list
					//alert(FlyTalk.views.ColumnView.tweetList);
					
					/*
					var PostStore = new Ext.data.JsonStore({
			model : 'PostModel',
			autoLoad: true,

			proxy: {
          		type: 'scripttag',
          		url: 'http://search.twitter.com/search.json',
          		extraParams: {
             		q: 'dumb',
                	rpp: 3,
                	//suppress_response_codes: true
          		},
          		reader: {
                	type: 'json',
                	root: 'results'
         		}
    		},
			
		});
			*/		
					
					FlyTalk.views.ColumnView.tweetList.bindStore(store); 
			
			
			
			
			
			
					//FlyTalk.views.TalkView.doLayout();			
					FlyTalk.views.TalkView.setActiveItem(FlyTalk.views.ColumnView, {type: 'slide', direction: 'right'});
					
				//	FlyTalk.views.searchResultsView17 = new FlyTalk.views.SearchResultsView();
			//var newpage = FlyTalk.views.searchResultsView17;
			//FlyTalk.views.TalkView.insert(0,  newpage);
				//	newpage.tweetList.bindStore(store);
			
				
			//alert(store.proxy.reader.rawData.totalCount);
	
			// update TalkView
			//FlyTalk.views.TalkView.doLayout();
			
			// display the search result page
			//FlyTalk.views.TalkView.setActiveItem(newpage, {type: 'slide', direction: 'right'});
					
					
					//list1.bindStore(store1); 
					//FlyTalk.views.TalkView.setActiveItem(options.next, {type: 'slide', direction: 'right'});
					
					//FlyTalk.views.searchResultsView = new FlyTalk.views.SearchResultsView();
				}
		});
},



/**
* DESCRIPTION:
* PARAMETERS: 
* RESULT:
*/

/*********************** DETAILS VIEW ***************************/
/**
* DESCRIPTION: get the ratings for each menu item
* PARAMETERS: 
*       restaurant - name of restaurant 
*       list - list to display the ratings
*       next - next page to display   
* RESULT: populate the supplied list with ratings for menu items
*/
'getMenuRating': function (options) {
		Ext.util.JSONP.request({
				url: 'http://yangjustine.startlogic.com/flytalk/flytalk1/db/dbRetrieveMultiple.php',
				callbackKey: 'callback',
				success: function() { Ext.Msg.alert('Success'); },
				failure: function() { Ext.Msg.alert('fail');},
				params: {
               			 method: 'getRecentFlightPosts',
            	},
				callback: function(data){
					var store = new Ext.data.JsonStore({
						model : 'MixedPostModel',
					});
					// load data into store
					store.loadData(data.results);
					// bind store to list
					options.list.bindStore(store); 
					FlyTalk.views.TalkView.setActiveItem(options.next, {type: 'slide', direction: 'right'});
				}
		});
},

});

FlyTalk.controllers.dbController = Ext.ControllerManager.get('dbController');